﻿using DNFImagePacks2Manager.Helpers;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;

namespace DNFImagePacks2Manager.NPK
{
    public class IMGHeader
    {

        private byte[] flagBytes;

        public string Flag { get; private set; }
        public int Size { get; set; }
        public int Temp { get; set; }
        public int Version { get; set; }
        public int Count { get; set; }

        public IMGHeader(BinaryReader reader)
        {

            flagBytes = reader.ReadBytes(16);
            byte[] sizeBytes = reader.ReadBytes(4);
            byte[] tempBytes = reader.ReadBytes(4);
            byte[] versionBytes = reader.ReadBytes(4);
            byte[] countBytes = reader.ReadBytes(4);

            Flag = ByteHelper.Bytes2String(flagBytes);
            Size = ByteHelper.Bytes2Int(sizeBytes);
            Temp = ByteHelper.Bytes2Int(tempBytes);
            Version = ByteHelper.Bytes2Int(versionBytes);
            Count = ByteHelper.Bytes2Int(countBytes);
        }

        public byte[] GetBytes()
        {
            List<byte> byteList = [];
            byteList.AddRange(flagBytes);
            byteList.AddRange(ByteHelper.IntList2Bytes([
                Size,
                Temp,
                Version,
                Count
                ]));
            return [.. byteList];
        }
    }
}
